<template>
  <div>
    <el-card title="用户管理" style="width: 100%" class="box-card sure-height">
      <div slot="header" class="clearfix">
        <span>订单管理</span>
      </div>
      <div
        style="
          float: right;
          padding: 3px 0;
          display: flex;
          position: relative;
          top: -12px;
        "
      >
        <el-input v-model="keyWord"></el-input
        ><el-button type="primary" size="small" @click="findSome()"
          >搜索</el-button
        ><el-button type="success" size="small" @click="addVisible = true"
          >新增</el-button
        >
      </div>
      <el-table
        :data="
          userData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
        "
        border
        style="width: 100%"
        :row-style="{ height: '100px' }"
      >
        <el-table-column prop="order_id" label="编号"> </el-table-column>
        <el-table-column prop="goodName" :show-overflow-tooltip="true" label="商品名"> </el-table-column>
         <el-table-column label="商品图片">
          <template slot-scope="scope"
            ><img
              style="width: 60px; height: 60px"
              :src="scope.row.goodImg"
              alt=""
          /></template>
        </el-table-column>
        <el-table-column prop="goodPrice" label="商品价格"></el-table-column>
        <el-table-column prop="goodNum" label="购买数量"></el-table-column>
        <el-table-column prop="timeOut" :show-overflow-tooltip="true" label="购买时间"></el-table-column>
        <el-table-column prop="address" :show-overflow-tooltip="true" label="收货地址"></el-table-column>
        <el-table-column prop="order_state" label="商品状态"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="shipOrder(scope.row)" :disabled="discover"
              >确认发货</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        align="center"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[1, 3, 5]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="userData.length"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { GetAllOrder ,ShipOrder} from "../../api/order";
export default {
  data() {
    return {
      discover:this.$store.state.discover,
      userData: [],
      keyWord: "",
      currentPage: 1,
      total: "",
      pageSize: 5,
    };
  },
  created() {
    let data = sessionStorage.getItem('state');
    if(data == null){
			this.$router.push('/login')
		}
    this.getAllOrder();
  },
  methods: {
    getAllOrder() {
      GetAllOrder().then((res)=>{
        console.log(res);
        this.userData = res.data.data
      })
    },
    shipOrder(row){
      ShipOrder({order_id:row.order_id}).then((res)=>{
        if(res.data.code == 200){
          this.$message.success("发货成功")
          this.getAllOrder();
        }
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
  },
};
</script>

<style scoped>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 480px;
}
.sure-height {
  height: 800px !important;
}
</style>